"use strict";

var myApp = angular.module('myApp.controllers',[]);

//myApp.controller('ConsultCtrl',function($scope, $http, $location, $routeParams) {
function DocumentCtrl($scope, $http, $location, $routeParams,PatientServices,MedecinServices) {
	$scope.block = true;
	
	$scope.patient = PatientServices.getGlobalPatient();
	
	$scope.addConsultation = function(block,title) {
		$scope.patient.consultations.push({block : block, title : title, date : "2014-12-01",content: ""});
	};
	
	$scope.savePatient = function(patient) {
		PatientServices.setGlobalPatient($scope.patient);
		PatientServices.writeData($scope.patient,function(status){(status!=200)?alert("problem occurred"):"";});
	};
	
	$scope.getPatient = function(name,surname,id) {
		PatientServices.readData(name,surname,id,function(data,status){
			(status==200)?$scope.patient=data:alert("An error occurred"); 
			updateWorkingOn("patient-document",PatientServices,MedecinServices);
		});
	};
	
	$scope.updateConsult = function(consultation) {
		PatientServices.setGlobalPatient($scope.patient);
	}
	
	$scope.printFicheBloc = function (){
		var win = window.open('','','left=0,top=0,width=1024px,height=748px,toolbar=0,scrollbars=0,status =0');

		var content = "<html>";
		content += "<body onload=\"window.print(); window.close();\">";
		content += document.getElementById("fiche_block").innerHTML ;
		content += "</body>";
		content += "</html>";
		win.document.write(content);
		win.document.close();
	}
	
	updateWorkingOn("patient-document",PatientServices,MedecinServices);

};

